#include<bits/stdc++.h>
using namespace std;
using i128 = __int128;
typedef long long ll;
typedef pair<int, int> PII;
#define fir first
#define sec second
#define pb push_back
#define int long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ref(i,a,b) for(int i=a;i>=b;i--)
const int N = 2e5, mod = 998244353, inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

int dx[] = { -1,0,1,0 };
int dy[] = { 0,1,0,-1 };



void solve()
{
	vector<pair<int, string>> a;
	for (int i = 0; i < 8; i++)
	{
		string s; int x;
		cin >> s >> x;
		a.push_back({ x,s });
	}
	vector<pair<int, string>> b;
	for (int i = 0; i < 8; i += 2)
	{
		if (a[i].first > a[i + 1].first) b.push_back(a[i]);
		else b.push_back(a[i + 1]);
	}
	a.clear();
	for (int i = 0; i < 4; i += 2)
	{
		if (b[i].first > b[i + 1].first) a.push_back(b[i]);
		else a.push_back(b[i + 1]);
	}
	sort(a.begin(), a.end());
	auto t1 = a[1], t2 = a[0];
	cout << t1.second << " beats " << t2.second << '\n';
}
/*
LNG 18
WBG 28
HLE 19
BLG 29
TES 48
T1 80
GEN 30
FLY 20
*/
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int T = 1;
	//cin>>T;
	while (T--) {
		solve();
	}
	return 0;
}